package com.swg.selector;

import com.swg.bean.Pig;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     *
     * @param annotationMetadata 当前类的注解信息
     * @param registry  beanDefinition注册类；
     *                   把所有需要添加进容器的bean：调用BeanDefinitionRegistry.registerBeanDefinition
     *                   来手工注册进来
     *
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
        boolean definition = registry.containsBeanDefinition("com.swg.bean.Pig");
        boolean definition2 = registry.containsBeanDefinition("com.swg.bean.Cat");
        if(definition && definition2){
            //指定bean定义信息
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Pig.class);
            //注册一个bean，指定bean的名字
            registry.registerBeanDefinition("pig",rootBeanDefinition);
        }
    }
}
